<article class="module width_full"> 
<header>
	<h3 class="tabs_involved">Danh sách đăng ký thực tập</h3>
	<input type='submit' value='Xoá' style='margin:5px;float:right;' onclick='deleteCompany();'/>
	<input type='submit' value='Xuất file' style='margin:5px;float:right;' onclick='window.location="<?php echo base_url('/index.php/admin/managecompany/export/'.$id);?>";'/>
</header>
<form action="<?php echo base_url('/index.php/admin/managecompany/signuplist/'.$id);?>" method="post" enctype="multipart/form-data" id="form">
<div class="tab_container">
	<div id="tab1" class="tab_content">
		<table class="tablesorter" cellspacing="0">
			<thead>
				<tr>
					<th><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></th>
					<th>ID</th>
					<th>Công ty</th>
					<th>Sinh viên</th>
					<th>CV</th>
					<th>Số lượng TTS</th>
					<th>Kết quả</th>
				</tr>
				<tr style="background: none;cursor:default;">
					<td></td>
					<td></td>
					<td>
						<select name="companyid" id="companyid" onchange="window.location = '<?php echo base_url();?>/index.php/admin/managecompany/signupList/'+$('#companyid').val();" style="height: 24px;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;background-color: white;">
							<option value="0">All</option>
							<option value="-1" <?php echo ($id==-1)?' selected':'';?>>Custom choice</option>
							<?php
							if (isset($companies) && is_array($companies)){
								foreach ($companies as $company){?>
							<option value='<?php echo $company->id;?>'<?php echo ($id == $company->id)?' selected':'';?>><?php echo $company->name;?></option><?php
								}
							}
							?>
						</select>
					</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</thead>
			<tbody>
				<?php if (isset($list) && is_array($list)) foreach ($list as $item){
				if (isset($item->traineeNum)){?>
				<tr>
					<td><input type="checkbox" name="selected[]" value="<?php echo $item->id.'|'.$item->userid;?>"/></td>
					<td><?php echo $item->id;?></td>
					<td><?php echo $item->name;?></td>
					<td><?php echo $item->user;?></td>
					<td><a href="<?php echo $item->cv;?>">CV</a></td>
					<td><?php echo $item->traineeNum;?></td>
					<td>
						<input type="radio" name="result<?php echo $item->id.'_'.$item->userid;?>" value="1" onclick="submitResult('<?php echo $item->id.'|'.$item->userid;?>',1);"<?php echo ($item->result==2)?' checked':'';?>/>Đồng ý
						<input type="radio" name="result<?php echo $item->id.'_'.$item->userid;?>" value="0" onclick="submitResult('<?php echo $item->id.'|'.$item->userid;?>',0);"<?php echo ($item->result==1)?' checked':'';?>/>Hùy
					</td>
				</tr>
				<?php }else{?>
				<tr>
					<td><input type="checkbox" name="selected[]" value="-<?php echo $item->id;?>"/></td>
					<td>Custom</td>
					<td><?php echo $item->name;?></td>
					<td><?php echo $item->user;?></td>
					<td><a href="<?php echo $item->cv;?>">CV</a></td>
					<td>N/a</td>
					<td>
					<input type="radio" name="result-<?php echo $item->id;?>" value="1" onclick="submitResult(-<?php echo $item->id;?>,1);"<?php echo ($item->result==2)?' checked':''?>/>Đồng ý
					<input type="radio" name="result-<?php echo $item->id;?>" value="0" onclick="submitResult(-<?php echo $item->id;?>,0);"<?php echo ($item->result==1)?' checked':''?>/>Hủy
					</td>
				</tr>
				<?php }?>
				<?php }?>
			</tbody>
		</table>
	</div>
	<!-- end of #tab1 -->
</div><!-- end of .tab_container --> 
</form>
</article><!-- end of content manager article -->
<script type="text/javascript">
	$(document).ready(function(){ 
		$(".tablesorter").tablesorter({headers:{0:{sorter:false},6:{sorter:false}}}); 
	});
</script>

<div id='delete-comfirm' style='display:none;'>
	Are you sure you want to delete these entries?
</div>
<script type="text/javascript">
	function deleteCompany(){
		$('#delete-comfirm').dialog("destroy");
		$('#delete-comfirm').dialog({
			height:180,
			width: 320,
			modal: true,
			title: 'Thuctap.com',
			buttons: {
                'Cancel': function(){
                    $( this ).dialog("close");
                },
				'Delete': function() {
					$("#form").submit();	
                }
			}
		});	
	}
	
	function submitResult($id,$result){
		$.ajax({
			url: '<?php echo base_url();?>/index.php/admin/managecompany/result',
			dataType: 'json',
			data: {
				'id':$id,
				'result':$result
			},
			type: "POST",
			success :function(data){
				if (data != 'Done') alert(data);
			}
		});
	}
</script>